package server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import db.DBmanager;

/**
 * Servlet implementation class LoginServlet
 */
public class UpdateGameData extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UpdateGameData() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName="";
		try{
		 userName=request.getParameterValues("userName")[0];
		}catch(Exception e){
			
			return;
		}
		System.out.println("update game");
		String regRes="";
		Locale loc= new Locale("he"); 
		response.setLocale(loc);
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out=response.getWriter();
		
		try{
			DBmanager.getDB().printDB();
			regRes=DBmanager.getDB().update(userName, "securityCheck" , request);
			if(regRes.equals("300")) {
				out.write("username/password does'nt match");
				response.setStatus(400);
			}else{
				System.out.println("SENT : "+regRes);
				response.setStatus(200);
				out.write(regRes);
			}
			return;
		}catch(Exception e){
			e.printStackTrace();
			out.write("we have encountred a technical problem, please login again");
			response.setStatus(400);
			return;
		}	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
